package io.renren.softpark.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.yunlong.common.utils.PageUtils;
import com.yunlong.common.utils.R;
import io.renren.softpark.dto.AddColumnDto;
import io.renren.softpark.dto.ColumnDetailDto;
import io.renren.softpark.dto.ColumnInfoDto;
import io.renren.softpark.dto.VerifyColumnDto;
import io.renren.softpark.entity.ColumnEntity;
import io.renren.softpark.form.AddColumnForm;
import io.renren.softpark.form.ColumnForm;
import io.renren.softpark.service.ColumnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 *
 * @author Cui
 * @email ${email}
 * @date 2020-08-14 09:24:18
 */
@RestController
@RequestMapping("generator/column")
public class ColumnController {
    @Autowired
    private ColumnService columnService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = columnService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 三级菜单
     * @return
     */
    @RequestMapping("/listTree")
    public R listTree(){
        List<AddColumnDto> columnDto = columnService.listTree();

        return R.ok().put("data", columnDto);
    }
    /**
     * 栏目审核的列表
     */
    @RequestMapping("/verify/list")
    public R verifyList(@RequestParam Map<String, Object> params){
        List<VerifyColumnDto> data = columnService.verifyColumn(params);

        return R.ok().put("data", data);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{columnId}")
    public R info(@PathVariable("columnId") String columnId){
		ColumnEntity column = columnService.getById(columnId);

        return R.ok().put("column", column);
    }


    /**
     * 修改column回显数据
     * @param columnId
     * @return
     */
    @RequestMapping("/columnInfo/{columnId}")
    public R columnInfo(@PathVariable("columnId") String columnId){
        ColumnInfoDto column = columnService.getEditColumn(columnId);
        return R.ok().put("column", column);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AddColumnForm column){
		columnService.saveColumn(column);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ColumnEntity columnEntity){
        columnService.updateById(columnEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/updateColumn")
    public R updateColumn(@RequestBody ColumnInfoDto columnInfoDto){
		columnService.updateColumnById(columnInfoDto);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] columnIds){
		columnService.removeByIds(Arrays.asList(columnIds));

        return R.ok();
    }

    /**
     * 包含栏目所有信息的接口
     */
    @RequestMapping("/detail")
    public R getDeatailData(@RequestBody ColumnForm columnForm){
        ColumnDetailDto columnDetailDto =columnService.getDetailData(columnForm.getColumnId());
        return R.ok().put("columnDetailDto",columnDetailDto);
    }

}
